import { resources } from "cc";
import Singleton from "./Singleton";
import { TextAsset } from "cc";
import { Message, Root, Type } from "protobufjs";
import proto from '../message/proto.js';


export default class NGameMessage extends Singleton{

    //通过类名获取类
    public getType(name:string):Type{
        return proto[name];
    }

    public DataToByte4(type:string,data:any):Uint8Array{
        if(!data){
            return new Uint8Array(0);
        }
        return this.getType(type).encode(data).finish();
    }

    public Byte4ToData(type:string,data:Uint8Array):Message{
        return this.getType(type).decode(data)
    }

}


